package org.skyeye.modeling.images;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImageConfigService {
	
	private HashMap<String,ImageConfig> imageConfigs = new HashMap<String,ImageConfig>();
	private static ImageConfigService instance = null;
	
	private ImageConfigService(){
		
	}
	
	public static ImageConfigService get(){
		if(instance==null){
			instance = new ImageConfigService();
		}
		return instance;
	}
	
	public ImageConfig getImageConfig(String configFileName){
		if(this.imageConfigs.containsKey(configFileName)){
			return this.imageConfigs.get(configFileName);
		}else{
			this.createImageConfig(configFileName);
			return this.getImageConfig(configFileName);
		}
	}
	
	public boolean createImageConfig(String configFileName){
		boolean rtValue = false;
		if(imageConfigs.containsKey(configFileName)){
			rtValue = false;
		}else{
			ImageConfig conf = new ImageConfig();
			conf.setConfigFileName(configFileName);
			imageConfigs.put(configFileName, conf);
			rtValue = true;
		}
		return rtValue;
	}
	
	public boolean deleteImageConfig(String configFileName){
		boolean rtValue = false;
		if(imageConfigs.containsKey(configFileName)){
			imageConfigs.remove(configFileName);
			rtValue = true;
		}
		return rtValue;
	}
	
	public boolean setSocOutMapping(String configFileName, String socName,Map<String,List<String>> outFileName){
		if(!this.imageConfigs.containsKey(configFileName)){
			this.createImageConfig(configFileName);
		}
		
		ImageConfig conf = this.imageConfigs.get(configFileName);
		conf.setSocOutFileMapping(socName, outFileName);
		this.imageConfigs.put(configFileName, conf);
		return true;
	}
	
	public void enableImageConfig(String configFileName){
		for(String name : this.imageConfigs.keySet()){
			if(name.equals(configFileName)){
				ImageConfig conf = this.imageConfigs.get(name);
				conf.setEnabled(true);
				this.imageConfigs.put(name, conf);
			}else{
				ImageConfig conf = this.imageConfigs.get(name);
				conf.setEnabled(false);
				this.imageConfigs.put(name, conf);
			}
		}
	}
}
